﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMaster.Master" AutoEventWireup="true" CodeBehind="Contact.aspx.cs" Inherits="MonitorPlan.Admin.Contact" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Contact Settings</title>
     <script>
        $(document).ready(function () {
            $("a#btnContactSetting").css("background", "#CCC");
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <%-- sqldatasource to get username --%>
            <asp:SqlDataSource ID="dsUser" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select userid, username from users where isdeleted=0"></asp:SqlDataSource>
             <%-- sqldatasource to get contact --%>
            <asp:SqlDataSource ID="dsContact" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select contact.*, users.userid,users.username from contact inner join users on contact.userid=users.userid"></asp:SqlDataSource>
             <%-- top menu for view and add new tool --%>
              <ul class="nav nav-pills action-buttons">
                <li><asp:LinkButton ID="btnView" runat="server" OnClick="btnView_Click">
                    <i class="icon icon-view"></i>&nbsp;View</asp:LinkButton></li>
                 <li>
                     <asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click">
                         <i class="icon icon-add"></i>&nbsp;Add New
                     </asp:LinkButton>
                 </li>
            </ul>

            <%-- multiview for insert, view, edit and detail view for contact --%>
            <asp:MultiView ID="mv" runat="server" ActiveViewIndex="0">
                <asp:View ID="vContact" runat="server">
                    <h5 class="text-info">View Contacts</h5>
                    <asp:Repeater ID="rp1" runat="server" DataSourceID="dsContact" OnItemCommand="rp1_ItemCommand">
                        <HeaderTemplate>
                             <table class="table table-condensed table-striped table-hover">
                                <tr>
                                    <th>Contact Id</th>
                                    <th>User Name</th>
                                    <th>User Id</th>
                                    <th>Contact</th>
                                    <th>Contact Type</th>
                                    <th>Actions</th>
                                </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <tr>
                                <td><%# Eval("contactid") %></td>
                                <td><%# Eval("username") %></td>
                                <td><%# Eval("userid") %></td>
                                <td><%# Eval("contact") %></td>
                                <td><%# Eval("contacttype") %></td>
                                 <td>
                                    <%-- the command button to edit, delete and view detail for each contact --%>
                                    <asp:LinkButton ID="btnDetail" runat="server"
                                        CommandName="detail" CommandArgument='<%# Eval("contactid") %>'>
                                        Detail</asp:LinkButton>&nbsp;
                                     <asp:LinkButton ID="btnEdit" runat="server" 
                                        CommandName="edit" CommandArgument='<%# Eval("contactid") %>'>
                                        Edit</asp:LinkButton>&nbsp;
                                    <asp:LinkButton ID="btnDelete" runat="server"
                                        CommandName="delete" CommandArgument='<%# Eval("contactid") %>' OnClientClick="return confirm('You want to delete it?');">
                                        Delete
                                    </asp:LinkButton>
                                </td>
                            </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
                </asp:View>
                <%-- view to add new tool --%>
                <asp:View ID="vNewContact" runat="server">
                    <h5 class="text-info">Add New Contact</h5>
                    <label for="ddlContactType">Contact Type</label>
                    <asp:DropDownList ID="ddlContactType" runat="server" AutoPostBack="false" Width="310">
                        <asp:ListItem Value="email">E-mail</asp:ListItem>
                        <asp:ListItem Value="phone">Phone</asp:ListItem>
                    </asp:DropDownList>
                    <label for="txtContact">Contact</label>
                    <asp:TextBox ID="txtContact" runat ="server" Width="300" placeholder="email or phone number"></asp:TextBox>
                    <label for="ddlUser">User Name</label>
                    <asp:DropDownList ID="ddlUser" runat="server" AutoPostBack="false" Width="310"
                         DataSourceID="dsUser" DataTextField="username" DataValueField="userid">

                    </asp:DropDownList>
                    <br />
                     <asp:LinkButton ID="btnSave" runat="server" CssClass="btn btn-primary btn-small" OnClick="btnSave_Click">
                        <i class="icon-ok-circle icon-white"></i> Save</asp:LinkButton>
                    <asp:LinkButton ID="btnCancel" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancel_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <asp:LinkButton ID="btnClose" runat="server" CssClass="btn btn-success btn-small" OnClick="btnClose_Click">
                        <i class="icon-arrow-left icon-white"></i> Back</asp:LinkButton>
                    <br /><br />
                    <div runat="server" id="actionSms"></div>
                </asp:View>
                <%-- view to edit a contact --%>
                <asp:View ID="vEdit" runat="server">
                     <h5 class="text-info">Edit Contact</h5>
                    <asp:HiddenField ID="txtid" runat="server" />
                    <label for="ddlConType">Contact Type</label>
                    <asp:DropDownList ID="ddlConType" runat="server" AutoPostBack="false" Width="310">
                        <asp:ListItem Value="email">email</asp:ListItem>
                        <asp:ListItem Value="phone">phone</asp:ListItem>
                    </asp:DropDownList>
                     <label for="txtCon">Contact</label>
                    <asp:TextBox ID="txtCon" runat ="server" Width="300"></asp:TextBox>
                    <label for="ddlUserName">User Name</label>
                    <asp:DropDownList ID="ddlUserName" runat="server" AutoPostBack="false" Width="310"
                         DataSourceID="dsUser" DataTextField="username" DataValueField="userid" OnSelectedIndexChanged="ddlUserName_SelectedIndexChanged">

                    </asp:DropDownList>
                     <br />
                    <asp:LinkButton ID="btnUpdate" runat="server" CssClass="btn btn-primary btn-small" OnClientClick="return confirm('You want to update?')" OnClick="btnUpdate_Click">
                        <i class="icon-ok-circle icon-white"></i> Update</asp:LinkButton>
                    <asp:LinkButton ID="btnCancelUpdate" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancelUpdate_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <div id="updateSms" runat="server"></div>
                </asp:View>
            </asp:MultiView>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
